package com.cyandpos.pad.member;

import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.posdata.Coupon;
import com.cyandpos.pad.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Derek on 2017/4/13.
 */

public class QueryMemberCouponAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<Coupon> mDatas;

    public QueryMemberCouponAdapter() {
        mDatas = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        View view = null;


        view = CommonUtils.getViewById(parent.getContext(), R.layout.item_memberinfo_coupondescribetype);
        viewHolder = new CouponHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (position % 2 != 0) {
            ((CouponHolder) holder).layout.setBackgroundResource(R.mipmap.yhq_odd);

        } else {
            ((CouponHolder) holder).layout.setBackgroundResource(R.mipmap.yhq_even);
        }

        ((CouponHolder) holder).tv_name.setText(mDatas.get(position).getCouponTypeName());
        ((CouponHolder) holder).tv_money.setText(String.valueOf(mDatas.get(position).getBalance()));
        ((CouponHolder) holder).tv_deadline.setText(mDatas.get(position).getValidDate());

    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    static class CouponHolder extends RecyclerView.ViewHolder {
        private TextView tv_name;
        private TextView tv_money;
        private TextView tv_deadline;
        private RelativeLayout layout;

        public CouponHolder(View itemView) {
            super(itemView);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_deadline = (TextView) itemView.findViewById(R.id.tv_deadline);
            layout = (RelativeLayout) itemView.findViewById(R.id.ll_background);
        }
    }

    public List<Coupon> getmDatas() {
        return mDatas;
    }

    public void setmDatas(List<Coupon> mDatas) {
        this.mDatas = mDatas;
    }

    public void addDatas(Coupon coupon) {
        mDatas.add(coupon);
    }
}
